//package com.example.smart_freezer;
//
//import android.annotation.SuppressLint;
//import android.app.AlarmManager;
//import android.app.Notification;
//import android.app.NotificationChannel;
//import android.app.NotificationManager;
//import android.app.PendingIntent;
//import android.app.Service;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.BitmapFactory;
//import android.os.Build;
//import android.os.IBinder;
//
//import java.util.Date;
//
//import androidx.core.app.AlarmManagerCompat;
//import androidx.core.app.NotificationCompat;
//
//
//// 暂时无用
///**
// * TRTC 屏幕分享崩溃解决方案
// * java.lang.SecurityException:
// * Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
// *
// * https://cloud.tencent.com/developer/article/1914827
// */
//public class MediaService extends Service {
//   private final String NOTIFICATION_CHANNEL_ID="com.tencent.trtc.apiexample.MediaService";
//   private final String NOTIFICATION_CHANNEL_NAME="com.tencent.trtc.apiexample.channel_name";
//   private final String NOTIFICATION_CHANNEL_DESC="com.tencent.trtc.apiexample.channel_desc";
//    public MediaService() {
//    }
//
//    @Override
//    public void onCreate() {
//        super.onCreate();
////        startNotification();
//
////        startAlarmNotification();
//    }
//
//    public void startNotification() {
//
//        // https://stackoverflow.com/questions/72919110/how-to-solve-this-targeting-s-version-31-and-above-requires-that-one-of-flag
//        // How to solve this Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//
//            int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
//
//            //Call Start foreground with notification
//            Intent notificationIntent = new Intent(this, MediaService.class);
//
//            @SuppressLint("WrongConstant") PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, flags);
//            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
//                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground))
//                    .setSmallIcon(R.drawable.ic_launcher_foreground)
//                    .setContentTitle("Starting Service")
//                    .setContentText("Starting monitoring service")
//                    .setContentIntent(pendingIntent);
//            Notification notification = notificationBuilder.build();
//            NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
//            channel.setDescription(NOTIFICATION_CHANNEL_DESC);
//            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//            notificationManager.createNotificationChannel(channel);
//
//            startForeground(1, notification); //必须使用此方法显示通知，不能使用notificationManager.notify，否则还是会报上面的错误
//        }
//    }
//
//    public void startAlarmNotification() {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {   // 26
//            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//
//            int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
//
//            //Call Start foreground with notification
//            Intent notificationIntent = new Intent(this, MediaService.class);
//
//            PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, flags);
//
////            AlarmManagerCompat.setExactAndAllowWhileIdle(
////                    alarmManager,
////                    AlarmManager.RTC_WAKEUP,
////                    1,
////                    pendingIntent
////            );
//
//            alarmManager.setRepeating(
//                    AlarmManager.RTC_WAKEUP,
//                    new Date().getTime(),
//                    AlarmManager.INTERVAL_DAY,
//                    pendingIntent
//            );
//
////            alarmManager.notify();
//        }
//
//    }
//
//
//
//    @Override
//    public IBinder onBind(Intent intent) {
//        throw new UnsupportedOperationException("Not yet implemented");
//    }
//}